home *** CD-ROM | disk | FTP | other *** search
/ Champak 33 / Volume 33 - JOGO DISK .iso / Games / pin_ball_deluxe.swf / scripts / DefineSprite_426 / frame_1 / DoAction.as < prev   
Text File  |  2007-01-15  |  6KB  |  231 lines

  1. function calculateDirection(angle)
  2. {
  3.    var _loc4_ = _X;
  4.    var _loc2_ = _Y;
  5.    var _loc3_ = x;
  6.    var _loc1_ = y;
  7.    a = _loc1_ - _loc2_;
  8.    b = _loc4_ - _loc3_;
  9.    c = (- _loc4_) * _loc1_ + _loc3_ * _loc2_;
  10. }
  11. function collisionSegment()
  12. {
  13.    var _loc2_ = segmentT.getIntersection(a,b,c);
  14.    var _loc4_ = segmentT.angle >= 90;
  15.    var _loc5_ = !_loc4_ ? segmentT.angle : 180 - segmentT.angle;
  16.    if(isCollision == true)
  17.    {
  18.       if(_loc5_ > 2)
  19.       {
  20.          speed += 1;
  21.       }
  22.    }
  23.    var _loc3_ = Math.sqrt((_loc2_.x0 - _X) * (_loc2_.x0 - _X) + (_loc2_.y0 - _Y) * (_loc2_.y0 - _Y));
  24.    _X = _loc2_.x0 - _loc3_ * (_width / 2) / actualDist * Math.cos(angle * radToDeg);
  25.    _Y = _loc2_.y0 - _loc3_ * (_width / 2) / actualDist * Math.sin(angle * radToDeg);
  26.    if(segmentT.clipObj != null)
  27.    {
  28.       segmentT.clipObj.action();
  29.    }
  30.    if(segmentT.clipObj == null)
  31.    {
  32.       segmentT.clipObj = _root.null_mc;
  33.       segmentT.clipObj.action();
  34.    }
  35.    speed += segmentT.clipObj.deltaSpeed;
  36.    angle = 2 * segmentT.angle - angle;
  37.    angle += angle >= 0 ? 0 : 360;
  38.    angle += angle <= 360 ? 0 : -360;
  39.    isCollision = true;
  40.    inactiveTuneling = true;
  41.    speedErr = 4.25;
  42.    if(speed > 6)
  43.    {
  44.       speed = speed - AMORTIZATION - speedErr;
  45.    }
  46.    if(speed > 3 && speed < 6)
  47.    {
  48.       speedErr = 1.6;
  49.       speed -= speedErr;
  50.    }
  51. }
  52. function collisionBall()
  53. {
  54.    var _loc7_ = ballT._x;
  55.    var _loc6_ = ballT._y;
  56.    var _loc11_ = _width / 2;
  57.    var _loc10_ = ballT._width / 2;
  58.    var _loc5_ = _loc11_ + _loc10_;
  59.    var _loc8_ = ballT.distancePoint(this);
  60.    _X = _loc7_ + _loc5_ * (x - _loc7_) / _loc8_;
  61.    _Y = _loc6_ + _loc5_ * (y - _loc6_) / _loc8_;
  62.    var _loc4_ = (- (_X - _loc7_)) / _loc5_;
  63.    var _loc3_ = (- (_Y - _loc6_)) / _loc5_;
  64.    var _loc2_ = speedX * _loc4_ + speedY * _loc3_;
  65.    var _loc9_ = (- speedX) * _loc3_ + speedY * _loc4_;
  66.    _loc2_ *= -1;
  67.    speedX = _loc2_ * _loc4_ - _loc9_ * _loc3_;
  68.    speedY = _loc2_ * _loc3_ + _loc9_ * _loc4_;
  69.    speed = Math.sqrt(speedX * speedX + speedY * speedY) + ballT.deltaSpeed;
  70.    angle = Math.atan(Math.abs(speedY / speedX)) * 180 / 3.141593;
  71.    if(speedX < 0 && speedY < 0)
  72.    {
  73.       angle += 180;
  74.    }
  75.    else if(speedX < 0 && speedY > 0)
  76.    {
  77.       angle = 180 - angle;
  78.    }
  79.    else if(speedX > 0 && speedY < 0)
  80.    {
  81.       angle = 360 - angle;
  82.    }
  83.    if(ballT.clipObj != null)
  84.    {
  85.       ballT.clipObj.action();
  86.    }
  87.    inactiveTuneling = true;
  88. }
  89. function collisionFlipperRight()
  90. {
  91.    var _loc5_ = _width / 2;
  92.    var _loc3_ = _root.flipRight.distanceTo(this);
  93.    var _loc7_ = x;
  94.    var _loc6_ = y;
  95.    var _loc4_ = Math.abs(_root.flipRight.centreX - x) / _root.flipRight.upSegment.module;
  96.    angle = 335 - Math.round(80 * _loc4_);
  97.    speed += 7 + 8 * _loc3_ / _root.flipRight.upSegment.module;
  98.    _root.flipRight.upSegment.active = false;
  99.    ballFlipped = true;
  100.    inactiveTuneling = true;
  101. }
  102. function collisionFlipperLeft()
  103. {
  104.    var _loc5_ = _width / 2;
  105.    var _loc3_ = _root.flipLeft.distanceTo(this);
  106.    var _loc7_ = x;
  107.    var _loc6_ = y;
  108.    var _loc4_ = Math.abs(x - _root.flipLeft.centreX) / _root.flipLeft.upSegment.module;
  109.    angle = 205 + Math.round(80 * _loc4_);
  110.    speed += 7 + 8 * _loc3_ / _root.flipLeft.upSegment.module;
  111.    _root.flipLeft.upSegment.active = false;
  112.    ballFlipped = true;
  113.    inactiveTuneling = true;
  114. }
  115. function findPossibleTarget()
  116. {
  117.    findPossibleSegmentTarget();
  118.    findPossibleBallTarget();
  119. }
  120. function findPossibleBallTarget()
  121. {
  122.    tempBalls = new Array();
  123.    for(var _loc5_ in _root.allBalls2)
  124.    {
  125.       if(_root.allBalls2[_loc5_].isPossibleTarget(this))
  126.       {
  127.          tempBalls.push(_root.allBalls2[_loc5_]);
  128.       }
  129.    }
  130.    if(tempBalls.length == 1)
  131.    {
  132.       ballT = tempBalls[0];
  133.       return undefined;
  134.    }
  135.    ballMinDistance = 100000;
  136.    var _loc4_ = -1;
  137.    for(_loc5_ in tempBalls)
  138.    {
  139.       var _loc3_ = tempBalls[_loc5_].distancePoint(this);
  140.       if(_loc3_ < ballMinDistance && (_loc3_ > 0 || ballT == tempBalls[_loc5_]))
  141.       {
  142.          ballMinDistance = _loc3_;
  143.          _loc4_ = _loc5_;
  144.       }
  145.    }
  146.    if(_loc4_ != -1)
  147.    {
  148.       ballT = tempBalls[_loc4_];
  149.    }
  150.    else
  151.    {
  152.       ballT = null;
  153.    }
  154. }
  155. function startClip()
  156. {
  157.    angle = startAngle;
  158. }
  159. function stepByStep()
  160. {
  161.    _X = _X + stepX;
  162.    _Y = _Y + stepY;
  163.    step++;
  164. }
  165. function updateDestination()
  166. {
  167.    if(inactiveTuneling == false)
  168.    {
  169.       isOnPath = false;
  170.    }
  171.    speed += speedInc == null ? 0.5 : speedInc;
  172.    if(MAX_SPEED < speed)
  173.    {
  174.       speed = MAX_SPEED;
  175.    }
  176.    antDestination = destination;
  177.    destination = _root[destination].nextStep;
  178.    if(destination == "out")
  179.    {
  180.       isOnPath = false;
  181.       angle = angleOut;
  182.       if(speedOut != null)
  183.       {
  184.          speed = speedOut;
  185.       }
  186.    }
  187.    else if(destination == "wait")
  188.    {
  189.       isOnPath = false;
  190.       speed = 0;
  191.       timeToWait = 2000;
  192.       speed_wait = _root[antDestination].speed_wait;
  193.       angle_wait = _root[antDestination].angle_wait;
  194.       sTime = getTimer();
  195.       inactiveTuneling = true;
  196.    }
  197.    else
  198.    {
  199.       deltaX = _root[destination]._x - _X;
  200.       deltaY = _root[destination]._y - _Y;
  201.       distanceToBeacon = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
  202.       steps = distanceToBeacon / speed;
  203.       stepX = deltaX / steps;
  204.       stepY = deltaY / steps;
  205.       step = 1;
  206.    }
  207. }
  208. function wait(time, ang_wait, spe_wait, xOut, yOut)
  209. {
  210.    timeToWait = time;
  211.    sTime = getTimer();
  212.    angle_wait = ang_wait;
  213.    speed_wait = spe_wait;
  214.    xOutPosition = xOut;
  215.    yOutPosition = yOut;
  216. }
  217. radToDeg = 0.017453;
  218. flipRightToggled = false;
  219. flipLeftToggled = false;
  220. speed = 0;
  221. startAngle = 270;
  222. GRAV_Y = 0.43;
  223. AMORTIZATION = 1.4;
  224. MAX_SPEED = 14;
  225. timeToWait = null;
  226. startClip();
  227. ballRadius = 4.3;
  228. activate = 0;
  229. m = 8.6;
  230. tempAngle = 0;
  231.